package com.kdfly.zmdfsj.activity;

import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.app.AppCompatActivity;
import android.support.v7.widget.AppCompatButton;
import android.view.View;

import com.kdfly.zmdfsj.MarketEvent;
import com.kdfly.zmdfsj.R;
import com.kdfly.zmdfsj.model.Constants;

import butterknife.BindView;
import butterknife.ButterKnife;
import de.greenrobot.event.EventBus;

/**
 * Created by Sean on 2016/3/6.
 */
public class GmActivity extends AppCompatActivity implements View.OnClickListener {
    @BindView(R.id.btn_gm_goto30) AppCompatButton btnGmGoto30;
    @BindView(R.id.btn_test_dialog) AppCompatButton btnTestDialog;
    @BindView(R.id.btn_test_frequent) AppCompatButton btnTestFrequent;

    @Override
    protected void onCreate(@Nullable Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_gm);
        ButterKnife.bind(this);
        btnGmGoto30.setOnClickListener(this);
        btnTestFrequent.setOnClickListener(this);
    }

    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.btn_gm_goto30:
                EventBus.getDefault().post(Constants.GOTO_DAY_30);
                break;
            case R.id.btn_test_dialog:
                break;
            case R.id.btn_test_frequent:
                int Probability = Constants.getRandom(300);
                MarketEvent m = null;

                if (Probability <= 50){
                    m = Constants.EVENTS_MARKET_One[Constants.getRandom(Constants.EVENTS_MARKET_One.length-1)];
                }if (Probability > 50 && Probability<= 90){
                m = Constants.EVENTS_MARKET_Two[Constants.getRandom(Constants.EVENTS_MARKET_Two.length-1)];
                }if (Probability > 90 && Probability<= 120){
                    m = Constants.EVENTS_MARKET_Three[Constants.EVENTS_MARKET_Three.length-1];
                }if (Probability > 120 && Probability<= 140){
                    m = Constants.EVENTS_MARKET_Four[Constants.getRandom(Constants.EVENTS_MARKET_Four.length-1)];
                }if (Probability > 140 && Probability<= 150){
                    m = Constants.EVENTS_MARKET_Five[Constants.getRandom(Constants.EVENTS_MARKET_Five.length-1)];
                }if (Probability > 150){
                    m = Constants.EVENTS_MARKET_Six[0];
                }

                System.out.println(getString(m.getMessageId()));
                break;
        }
    }
}
